//package com.songlanyun.modules.rabbitmq.mq.consumer;
//
//import com.alibaba.fastjson.JSONObject;
//import com.rabbitmq.client.Channel;
//import com.songlanyun.common.utils.DateUtil;
//import com.songlanyun.modules.rabbitmq.DelayedConstant;
//import com.songlanyun.modules.rabbitmq.MqConstant;
//import com.songlanyun.modules.rabbitmq.entity.MsgLog;
//import com.songlanyun.modules.rabbitmq.service.MessageHelper;
//import com.songlanyun.modules.rabbitmq.service.MsgLogService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.core.MessageProperties;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//import java.time.LocalDateTime;
//import java.util.Arrays;
//import java.util.Date;
//
//@Component
//@Slf4j
//public class OrderDelayedConsumer {
//
//    @Autowired
//    private MsgLogService msgLogService;
//
//
//    @RabbitListener(queues = DelayedConstant.OrderDelayedConstant.ORDER_DELAYED_QUEUE)
//    public void consume(Message message, Channel channel) throws IOException {
//        //1--- 取消息id
//        String msgId = message.getMessageProperties().getMessageId();
//        log.info("接收消息, msgId: {},时间：{}", msgId, DateUtil.getNowTime("yyyy-MM-DD HH:mm:ss"));
//
//        JSONObject msgBody = MessageHelper.msgToObj(message, JSONObject.class);
//        String msg = msgBody.toJSONString();
//        //2---判断消息是否被消费，如果消费则不管
//        MsgLog msgLog = msgLogService.selectByMsgId(msgId);//
//        if (null == msgLog || msgLog.getStatus().equals(MqConstant.MsgLogStatus.CONSUMED_SUCCESS)) {// 消费幂等性
//            log.info("重复消费, msgId: {}", msgId);
//            return;
//        }
//
//        MessageProperties properties = message.getMessageProperties();
//        // deliveryTag 用来回传告诉 rabbitmq 这个消息处理成功 清除此消息（basicAck方法）。
//        long tag = properties.getDeliveryTag();
//        boolean success = true;
//        if (success) {
//            msgLogService.updateStatus(msgId, MqConstant.MsgLogStatus.CONSUMED_SUCCESS);
//            //3-----调用正常的逻辑处理，如果逻辑处理成功 清除此消息
//            //根据订单号来查询此订单支付状态是否支付，如无，则进行取消的业务逻辑处理
//
//            // if (执行结棍result()==1)  channel.basicAck(tag, false);
//            channel.basicAck(tag, false);// 消费确认 未被ack的消息(unacked)会重新入队并被消费, 这样就保证了消息不会走丢
//        } else {
//            channel.basicNack(tag, false, true);
//        }
//    }
//
//}